using System;
using GameFramework.Event;
using UnityEngine;
using Unity.VisualScripting;
using UnityGameFramework.Runtime;

namespace LS.UGFUnits
{
    [UnitShortTitle("Close")]
    [UnitSurtitle("UI Form")]
    public sealed class CloseUIFormByInstance : UIUnit
    {
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput Instance { get; private set; }
        
        protected override void Definition()
        {
            base.Definition();
            Instance = ValueInput<UIForm>(nameof(Instance), null);
            Requirement(Instance, Input);
            Succession(Input, Output);
        }

        protected override ControlOutput In(Flow flow)
        {
            UIForm instance = flow.GetValue<UIForm>(Instance);
            Target?.CloseUIForm(instance);
            return base.In(flow);
        }
    }
}